<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('台账填报')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>部门：</p>
                            <input type="text" name=""/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()">
                <i class="fa fa-plus"></i> 添加
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:src="@{/js/activiti.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "settlement";
    var currentUser = [[${currentUser}]];

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            detailUrl: prefix + "/edit/{id}",
            sortName: "applyTime",
            sortOrder: "desc",
            modalName: "台账",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'compName',
                    title: '工程公司'
                },
                {
                    field: 'numberText',
                    title: '编号'
                },
                {
                    field: 'proName',
                    title: '项目名称'
                },
                {
                    field: 'auditContent',
                    title: '审核内容'
                },
                {
                    field: 'teamInfo',
                    title: '分包班组信息'
                },
                {
                    field: 'applyMoney',
                    title: '申请金额'
                },
                {
                    field: 'taskName',
                    title: '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return '<span class="badge badge-primary">' + value + '</span>';
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.instanceId) {
                            actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\',1400,700)"><i class="fa fa-eye"></i> 表单数据</a> ');
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="showHistoryDialog(\'' + row.instanceId + '\')"><i class="fa fa-list"></i> 审批历史</a> ');
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="showProcessImgDialog(\'' + row.instanceId + '\')"><i class="fa fa-image"></i> 进度查看</a> ');
                        } else {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="submitApply(\'' + row.id + '\',\'' + row.createBy + '\')"><i class="fa fa-user"></i> 提交</a> ');
                            actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="editForm(\'' + row.id + '\',\'' + row.createBy + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="removeForm(\'' + row.id + '\',\'' + row.createBy + '\')"><i class="fa fa-remove"></i> 删除</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function submitApply(id, createBy) {
        if (createBy !== currentUser.loginName) {
            $.modal.alertWarning("不允许非创建人提交申请！");
            return;
        }
        $.modal.confirm("确认要提交申请吗?", function () {
            var url = prefix + "/submitApply";
            var data = {"id": id};
            $.operate.submit(url, "post", "json", data);
        });
    }

    function editForm(id, createBy) {
        if (createBy !== currentUser.loginName) {
            $.modal.alertWarning("不允许非创建人编辑表单！");
            return;
        }
        $.operate.editFull(id);
    }

    function removeForm(id, createBy) {
        if (createBy !== currentUser.loginName) {
            $.modal.alertWarning("不允许非创建人删除表单！");
            return;
        }
        $.operate.remove(id);
    }

    function cancelApply(instanceId, createBy) {
        if (createBy !== currentUser.loginName) {
            $.modal.alertWarning("不允许非创建人撤销申请！");
            return;
        }
        $.modal.confirm("确认要撤销申请吗?", function () {
            var url = ctx + "process/cancelApply";
            var data = {"instanceId": instanceId};
            $.operate.submit(url, "post", "json", data);
        });
    }

    function suspendOrActiveApply(instanceId, createBy, suspendState) {
        var suspendOrActive = suspendState === '2' ? '激活' : '挂起';
        if (createBy !== currentUser.loginName) {
            $.modal.alertWarning("不允许非创建人" + suspendOrActive + "申请！");
            return;
        }
        $.modal.confirm("确认要" + suspendOrActive + "申请吗?", function () {
            var url = ctx + "process/suspendOrActiveApply";
            var data = {"instanceId": instanceId, "suspendState": suspendState};
            $.operate.submit(url, "post", "json", data);
        });
    }
</script>
</body>
</html>
